package chap04;

import java.math.BigDecimal;
import java.util.Random;

public class BigDecimal_test {
    static int arr[]=new int [10];
     public static void main(String[] args){
        BigDecimal_Demo();
        System.out.println("随机数测试");
        Random();
     }
     public static void BigDecimal_Demo(){
         BigDecimal op1=new BigDecimal("3.141592");
         BigDecimal op2=new BigDecimal("3");
         System.out.println(op1.add(op2));
         System.out.println(op1.subtract(op2));
         System.out.println(op1.multiply(op2));
         System.out.println(op1.divide(op2, BigDecimal.ROUND_UP));
         System.out.println(op1.negate());
     }
     public static void Random(){
         Random randomObj=new Random();
         int ctr=0;
         int zheng=0,fan=0;
         while(ctr<10){
             float val=randomObj.nextFloat();
               if(val<0.5){
                   zheng++;
               }
               else{
                   fan++;
               }
               ctr++;
         }
         System.out.println("正面"+zheng+"次");
         System.out.println("反面" + fan + "次");

         StringBuffer ch = new StringBuffer("Java Apple");
      ch.reverse();
         System.out.println(ch.toString());
     }
}
